package com.yenlien.traceyun.plant.dao;


import com.yenlien.traceyun.plant.entity.DevAlarm;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jialong
 * @date 2023/8/1
 * @description:
 **/

public interface DevAlarmDao extends BaseJpaDao<DevAlarm> {



    @Transactional
    @Modifying
    @Query(value = "UPDATE dev_alarm SET  handle_state = '2' WHERE id IN (?1)", nativeQuery = true)
    int handle(List<String> idList);


    @Query(value = "SELECT base_soil_name FROM dev_alarm WHERE comp_id = ?1", nativeQuery = true)
    List<String> getAlarmBaseSoil(String companyId);


    @Query(value = "SELECT * FROM dev_alarm WHERE comp_id = ?2 AND alarm_type = '1' ORDER BY `create_time` DESC LIMIT ?1", nativeQuery = true)
    List<DevAlarm> getHistoryDataNum(Integer num, String companyId);


    @Query(value = "SELECT id FROM dev_alarm WHERE param_name = ?1 AND dev_id = ?2 AND DATE(create_time) = CURDATE()", nativeQuery = true)
    List<String> getIdByParamNameAndDevId(String paramName, String devId);


    @Query(value = "SELECT id FROM dev_alarm WHERE dev_id = ?1 AND alarm_type = '2' AND DATE(create_time) = CURDATE()", nativeQuery = true)
    List<String> getAlarmByDevId(String devId);

}
